from collections import deque
def BellmanFord(edges_value, N, start):
    min_dist = [float('inf')] * (N+1)
    min_dist[start] = 0
    
    queue = deque()
    queue.append(start)
    while queue:
        s = queue.popleft()
        for t, val in edges_value[s]:
            if min_dist[s] != float('inf') and min_dist[s]+val < min_dist[t]:
                min_dist[t] = min_dist[s]+val
                queue.append(t)
    return min_dist
        
        
            
def main():
    N, M = map(int, input().split())
    edges_value = [[] for i in range(N+1)]
    for i in range(M):
        s, t, value = map(int, input().split())
        edges_value[s].append([t, value])
    
    
    min_dist = BellmanFord(edges_value, N, 1)
    if min_dist[-1] == float('inf'):
        print("unconnected")
    else:
        print(min_dist[-1])
    
main()